
local mt = ac.skill['召唤单位']
mt.art = [[ReplaceableTextures\CommandButtons\BTNBlizzard.blp]]
mt.temp = '自动释放'
mt.cooling_flag = true
mt.summon_count = 1
mt.summon_max = -1
mt.summon_time = 30
mt.summon_unit = 'hfoo'

function mt:on_run(hero)
    local angle = hero:get_facing()
    local point = hero:get_point() - {angle,150}
    local temp = self:create_cast()
    local okey = temp.summon_group or self.summon_unit
    local group = hero:get_data(okey) or {}
    if self:notify('chek_summon',group) then
        return
    end
    if hero:dispatch('单位-拦截召唤',hero,temp) then
        return
    end
    local has = {}
    for _,unit in ipairs(group) do
        if unit:is_alive() then
            if self.summon_max>0 and #has + temp.summon_count>self.summon_max then
                unit:kill()
            else
                table.insert(has,unit)
            end
        end
    end
    for a=1,temp.summon_count do
        local enter = point:find_summon_point(512,angle) or point
        local unit = hero:create_unit(temp.summon_unit,enter,angle)
        unit_add_life2(unit)
        temp:notify('set_summon',unit)
        unit:add_buff('召唤物'){time = temp.summon_time,source = hero}
        table.insert(has,unit)
    end
    hero:set_data(okey,has)
end
